/**
 * Created by chenqiailai on 17/9/10.
 */
$(function () {
   var reData = eval('(' +  localStorage.res + ')');
   // console.log('接收',reData);

    function compare(property){
        return function(a,b){
            var value1 = a[property];
            var value2 = b[property];
            return value2 - value1;
        }
    }
   var newData=reData.sort(compare('score'));

    bindSubmit(newData);
    function bindSubmit(data){
        var str=$("#detailList").html();
        var res=ejs.render(str, {data: data});
        $(".page-sty").html(res);
    }


  // var indicator_empty_data = ['开放性', '外向性', '神经质', '宜人性', '尽责性'];


   var features=[];
    $('.features').each(function(){
        features.push($(this).text());
    });
    var newData=[];
     for(var i=0;i<reData.length;i++){
         newData.push(reData[i].score);
     }


    var dom = document.getElementById("map");
    var myChart = echarts.init(dom);
    var indicator_data = [];
    for (var i = 0; i < features.length; i++) {
        indicator_data.push({text: features[i], max: 100});
    }
    var rander = {

        axisLine: {
            lineStyle: {
                color: '#ffde32'
            }
        },
        splitLine: {
            lineStyle: {
                color: '#ffde32'
            }
        },

        splitArea: {
            areaStyle: {
                color: ['#fffbe3',
                    '#fffbe3', '#fffbe3',
                    '#fffbe3', '#fffbe3'],
                shadowColor: '#fffbe3',
                shadowBlur: 10
            }
        },
        name: {
            textStyle: {
                color: '#000',
                backgroundColor: '#fffbe3',
                borderRadius: 3,
                padding: [3, 5]
            }
        },
        indicator: indicator_data,
    };
    option = {
        title: {
            text: ''
        },

        tooltip: {},
        legend: {

        },
        radar: rander,
        series: [{
            name: '',
            //symbol: "none",//拐点
            type: 'radar',
            itemStyle: {
                normal: {
                    color:"#8ee9f6",
                    lineStyle: {
                        color:"#8ee9f6" // 图表中各个图区域的边框线颜色
                    },
                    areaStyle: {
                        type: 'default'
                    }
                }
            },
            data : [
                {
                    value :newData,
                    areaStyle: {
                        normal: {
                            opacity: 0.9,
                            color: new echarts.graphic.RadialGradient(0.5, 0.5, 1, [
                                {
                                    color: '#8ee9f6',
                                    offset: 0
                                },
                                {
                                    color: '#8ee9f6',
                                    offset: 1
                                }
                            ])
                        }
                    }
                }

            ]
        }]
    };

    myChart.setOption(option, true);



    if(navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1){
        $('.page-sty').css('overflow','auto');
        $('.chara_list').on('touchend',function(){
            $('.cold-fusion .report').stop().animate({bottom: 0}, 500);
            $('.pull-down').hide();
        })
    }else{
        $(".cold-fusion").swipe( {
            swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
                if(direction=='up'){
                        $('.head').stop().slideUp();
                        $('.pull-down').hide();
                        $('.cold-fusion .chara_list').css('margin', '50px auto');
                        $('.cold-fusion .report').stop().animate({bottom: 0}, 300);
                        $('.page-sty').css('overflow','auto');
                }
                if(direction=='down'){
                        $('.head').stop().slideDown();
                        $('.cold-fusion .report').stop().animate({bottom: '-50%'}, 300);
                        $('.cold-fusion .chara_list').css('margin', '90px auto');
                        $('.pull-down').show();
                    }
            },
            threshold:0
        });
    }

})